package com.elab.model;
/**
 * API接口的基础返回类
 *
 * @author Emoker
 * @version 1.0
 * @since 2018/1/7
 */
public class BaseResponse {
	/**
     * 是否成功
     */
    private boolean success;
    
    /**
     * 结果码
     */
    private int code;

    /**
     * 说明
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;

    public BaseResponse() {

    }

    public BaseResponse(boolean success, int code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
    
	public static BaseResponse ok () {
		return new BaseResponse(true, 0, "success", null);
	}
	
	public static BaseResponse ok (String msg, Object data) {
		return new BaseResponse(true, 0, msg, data);
	}
	
	public static BaseResponse ok (int code, String msg, Object data) {
		return new BaseResponse(true, 0, msg, data);
	}
	
	public static BaseResponse fail () {
		return new BaseResponse(false, 1, "error", null);
	}
	
	public static BaseResponse fail (int code, String msg) {
		return new BaseResponse(false, code, msg, null);
	}
	
	public static BaseResponse fail (int code, String msg, Object data) {
		return new BaseResponse(false, code, msg, data);
	}
    
}
